package cn.edu.scau.cmi.lijinzhao.comprehensive;

import java.util.*;
public class scoreList {
    int maxLength = 100;
	int length = 0;
	double ac,bc,cc,dc,ec;
	int a = 0,b=0,c=0,d=0,e=0;
    Score[] data = new Score[maxLength];
    
	Scanner input = new Scanner(System.in);
	
	public scoreList() {
	
	}
	
	//添加记录方法
	public void add() {
			if(length < maxLength) {
				data[length] = new Score();
				System.out.print("请输入学生的学号： ");
				data[length].setNum(input.next());
				System.out.print("请输入学生的姓名：");
				data[length].setName(input.next());
				//attendanceScore,testScore,homeworkScore,finalScore,totalScore,考勤、测验、作业、期末，并对成绩汇总
				
				System.out.print("请输入学生的考勤成绩：");
				data[length].setattendanceScore(input.nextDouble());
				
				System.out.print("请输入学生的测验成绩：");
				data[length].settestScore(input.nextDouble());
				
				System.out.print("请输入学生的作业成绩：");
				data[length].sethomeworkScore(input.nextDouble());
				
				System.out.print("请输入学生的期末成绩：");
				data[length].setfinalScore(input.nextDouble());
				
				System.out.print("请输入学生的总评成绩：");
				data[length].settotalScore(input.nextDouble());
				
				length++;
				
				
				System.out.println("添加成功！");
			}
			else {
				System.out.println("添加失败！");
			}
	}
	
	//计算
	//计算
	public void rank(int length){
		for(int i = 0; i < length; i++) {
		if(data[i].totalScore>89) {
			a=a+1;
		}
		
		if(data[i].totalScore>79&&data[i].totalScore<90) {
			b=b+1;
		}
		
		if(data[i].totalScore>69&&data[i].totalScore<80) {
			c=c+1;
		}
		
		if(data[i].totalScore>59&&data[i].totalScore<70) {
			d=d+1;
		}
		
		if(data[i].totalScore<60) {
			e=e+1;
		}
		}
		 ac=(a/length)*100;
		 bc=(b/length)*100;
		 cc=(c/length)*100;
	     dc=(d/length)*100;
		 ec=(e/length)*100;
	}
	

	//显示成绩单方法
	public void transcript() {
		System.out.println("课程："+data[1].course);
		System.out.println("教师："+data[1].teacher);
		System.out.println("班级："+data[1].Class);
		System.out.println("===========================================================================================================");
		System.out.println(" 学号                   姓名                  考勤                    测验                    作业                    期末                     总评 ");
		for(int i = 0; i < length; i++) {
			System.out.println(data[i].num + "\t" + data[i].name + "\t"+ data[i].attendanceScore + "\t"+ data[i].testScore + "\t"+ data[i].homeworkScore + "\t"+ data[i].finalScore + "\t"+ data[i].totalScore);
		}
		System.out.println("===========================================================================================================\n");
		System.out.println(" 成绩区段                  人数                  百分比     ");
		
		System.out.println(" 90-100           "+a+           +ac+"%"      );
		System.out.println(" 80-89            "+b+           +bc+"%"      );
		System.out.println(" 70-79            "+c+           +cc+"%"      );
		System.out.println(" 60-69            "+d+           +dc+"%"      );
		System.out.println(" 0 -59            "+e+           +ec+"%"      );
		
		
	}
	
	//统计成绩以及人数算百分比

		
	//删除学生记录方法
	public void delete() {
		System.out.print("请输入您要删除信息的学生的学号: ");
    	String number1 = input.next();
		int i, flag = length;
		for(i = 0; i < length; i++) {
			if(number1.equals(data[i].num)) {
				flag = i; break;
			}
			}
		if(i == length) {
			System.out.println("查无此人！请核对后重新输入 \n");
			delete();
		}
		else {
			for(int j = flag; j < length; j++) {
				data[j] = data[j + 1];
			}
			System.out.println("删除成功！\n");
			length -= 1; //不减1会报数组越界的错误
		}
	}
	
	
	//查询某个学生信息方法
	public void inquire() {
		System.out.print("请输入您要查询成绩的学生的学号：");
    	String number2 = input.next();
		int i;
		for(i = 0; i < length; i++) {
			if(number2.equals(data[i].num)) {
				System.out.println("===========================================================================================================");
				System.out.println(" 学号                   姓名                  考勤                    测验                    作业                    期末                     总评 ");
				for( i=0; i < length; i++) {
					System.out.println("课程："+data[i].course);
					System.out.println("教师："+data[i].teacher);
					System.out.println("班级："+data[i].Class);
					System.out.println(data[i].num + "\t" + data[i].name + "\t"+ data[i].attendanceScore + "\t"+ data[i].testScore + "\t"+ data[i].homeworkScore + "\t"+ data[i].finalScore + "\t"+ data[i].totalScore);
				}
				System.out.println("===========================================================================================================\n");
				break;
			}
			}
		if(i == length) {
			System.out.println("查无此人！请核对后重新输入学号 \n");
			inquire();
		}
	}
	
	//修改学生信息方法
	public void recompose() {
		System.out.print("请输入您要修改信息的学生的学号：");
    	String number3 = input.next();
		int i;
		for(i = 0; i < length; i++) {
			if(number3.equals(data[i].num)) {
				System.out.println("请输入该学生新的学号，姓名和课程，教师以及班级：");
				data[i].setNum(input.next());
				data[i].setName(input.next());
				System.out.print("请输入学生的考勤成绩：");
				data[i].setattendanceScore(input.nextDouble());
				
				System.out.print("请输入学生的测验成绩：");
				data[i].settestScore(input.nextDouble());
				
				System.out.print("请输入学生的作业成绩：");
				data[i].sethomeworkScore(input.nextDouble());
				
				System.out.print("请输入学生的期末成绩：");
				data[i].setfinalScore(input.nextDouble());
				
				System.out.print("请输入学生的总评成绩：");
				data[i].settotalScore(input.nextDouble());
				System.out.println("修改成功！\n");
				break;
			}
			}
		if(i == length) {
			System.out.println("查无此人！请核对后重新输入学号\n");
			recompose();
		}
	}
}